package com.yami.shop.api.controller;

import com.yami.shop.bean.app.dto.SkuDto;
import com.yami.shop.bean.model.Sku;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.service.SkuService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import com.yami.shop.common.util.BeanUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author LGH
 */
@RestController
@RequestMapping("/sku")
@Tag(name = "sku规格接口")
@AllArgsConstructor
public class SkuController {

    private final SkuService skuService;



    @GetMapping("/getSkuList")
    @Operation(summary =  "通过prodId获取上架的规格列表", description = "通过prodId获取上架的规格列表")
    @Parameter(name = "prodId", description = "商品id")
    public ServerResponseEntity<List<SkuDto>> getSkuListByProdId(Long prodId) {
        List<Sku> skus = skuService.listPutOnSkuAndSkuStock(prodId);
        List<SkuDto> skuDtoList = BeanUtil.mapAsList(skus, SkuDto.class);
        return ServerResponseEntity.success(skuDtoList);
    }
}
